#!/bin/bash
# vim: fdm=marker fmr=[[[,]]] cms=\ #%s

main()
{
    local cmdir=$SVCENV_DIR/src/cm
    if [[ $PWD != $cmdir ]]
    then
        echo "Error: current dir not $cmdir"
        return 1
    fi

    local src=$1.c
    local obj=$1.o
    if [[ ! -f $src ]]
    then
        echo "Error: $src not found"
        return 1
    fi

    local CFLAGS="-c -g -Wall"
    local INCLS="-I$SVCENV_DIR/src/include -I$SOAR/common/c/include"
    if [[ $MYSQL_HOME ]]
    then INCLS="$INCLS -I$MYSQL_HOME/include"; fi 
    $CC $INCLS $CFLAGS -o $obj $src
    if (( $? != 0 ))
    then
        echo "Error: compile fail"
        return 1
    fi

    local libcm=$SVCENV_DIR/lib/libcm.a
    ar -crl $libcm $obj
    chmod 666 $libcm
    rm -f $obj
}

main $@
exit $?
